<template>
  <div>
    <el-form
      ref="form"
      :rules="rules"
      :model="form"
      label-width="100px"
      label-position="left"
    >
      <el-form-item v-if="isadd" label="会员等级:" prop="level">
        <el-select
          v-model="form.level"
          style="width: 100%"
          placeholder="请选择会员等级"
        >
          <el-option
            v-for="(item, index) in levelList"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="isadd" label="有效期:" prop="time">
        <el-select
          v-model="form.time"
          placeholder="请选择日期"
          style="width: 100%"
        >
          <el-option
            v-for="(item, index) in timeList"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户名:" prop="name">
        <el-input v-model="form.name" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="昵称:" prop="nickname">
        <el-input v-model="form.nickname" placeholder="请输入昵称"></el-input>
      </el-form-item>
      <el-form-item label="手机号:" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-form-item label="密码:" prop="password">
        <el-input
          v-model="form.password"
          type="password"
          placeholder="请输入密码"
          show-password
        ></el-input>
      </el-form-item>
      <el-form-item label="渠道:" prop="qudao">
        <el-select
          v-model="form.qudao"
          placeholder="请选择渠道"
          style="width: 100%"
        >
          <el-option
            v-for="(item, index) in qudaoList"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="!isadd" label="登录时间:">
        <div>2023-06-26  07:47:31 </div>
      </el-form-item>
      <el-form-item v-if="!isadd" label="注册时间:">
        <div>2023-06-26  07:47:31 </div>
      </el-form-item>
      <el-form-item label="状态:" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div class="flexend">
      <el-button type="primary" @click="onSubmit">确 认</el-button>
      <el-button @click="resetForm">重 置</el-button>
    </div>
  </div>
</template>

<script>
import { validPhone } from "@/utils/validate";
export default {
  data() {
    return {
      levelList: [
        { label: "免费版", value: 1 },
        { label: "专业版", value: 2 },
        { label: "旗舰版", value: 3 },
      ],
      timeList: [
        { label: "1个月", value: 1 },
        { label: "一个季度", value: 2 },
        { label: "一年", value: 3 },
      ],
      qudaoList: [
        { label: "用户端", value: 1 },
        { label: "小程序", value: 2 },
        { label: "H5", value: 3 },
        { label: "电销业务员", value: 4 },
        { label: "系统管理员", value: 5 },
      ],
      form: {
        level: "",
        time: "",
        name: "",
        nickname: "",
        phone: "",
        password: "",
        qudao: "",
        status: 1,
      },
      rules: {
        level: [
          { required: true, message: "请选择会员等级", trigger: "change" },
        ],
        time: [{ required: true, message: "请选择有效期", trigger: "change" }],
        name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        nickname: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { validator: validPhone, trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        qudao: [{ required: true, message: "请选择渠道", trigger: "change" }],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
      },
    };
  },
  props:{
    isadd:{
       type:Boolean,
       default:true
    }
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (!valid) return;
      });
    },

    resetForm() {
      this.$refs.form.resetFields();
    },
  },
};
</script>